import $ from 'jQuery';
(function () {
    let $vue = new Vue({
        el: '.main-hook',
        data: {
            leaseType: [{id: 1, name: '主动告警'}, {id: 2, name: '人工告警'}],
            orderStatus  : [{id: 0, name: '电容故障'}, {id: 1, name: '光源故障'}, {id: 2, name: '继电器故障'}, {id: 3, name: '保险丝故障'},
                {id: 4, name: '存储芯片故障'}, {id: 5, name: '时钟芯片故障'}, {id: 6, name: '读卡模块故障'}, {id: 7, name: '内部参数配置故障'},
                {id: 8, name: '漏电报警'}, {id: 9, name: '防盗报警'}, {id: 10, name: '水浸报警'}, {id: 11, name: '电流过大报警'},
                {id: 12, name: '功率过大报警'}, {id: 13, name: '功率过小报警'}, {id: 14, name: '其他'}],
            paymentFlag:[{id:1,name:'待签收'},{id:2,name:'待处理'},{id:3,name:'待审核'},{id:4,name:'待派单'},{id:5,name:'已完成'},{id:6,name:'已废弃'}],
            key:[{id:1,name:'告警编号'},{id:2,name:'单灯编号'},{id:3,name:'灯杆编号'},{id:4,name:'工单编号'}],
            boxs: {
                box1: {show: true, hook: '.box1-hook', lock: true, url: '', params: {}},
                box2: {show: false, hook: '.box2-hook', url: '', params: {}},
                box3: {show: false, hook: '.box3-hook', url: '', params: {}},
                box4: {show: false, hook: '.box4-hook', url: '', params: {}}
            },
            roleList: []
        },
        created: function () {
            M.Request.getRoleList(true, (roleList, ret) => {
                this.roleList = roleList;
            });
        },
        methods: {
            emitPage: function () {
                M.Page.load(this.boxs);
            },
            // 上一页
            prePage: function () {
                M.Page.prePage(this.boxs);
            },
            searchKey:function(){
                $('.search-hook').trigger('click');
            },
            // 触发刷新页(当前显示的页面)
            refreshPage: function () {
                M.Page.refreshPage(this.boxs);
            }
        },
        mounted: function () {
            let thiz = this;
            this.$nextTick(() => {
                let $accountBox = $('.order-hook');
                let $tableHookName = $('.order-table-hook');
                var $form = $accountBox.find('.form-search-hook');
                //初始化时间插件
                modal.initDate("startdate","enddate");
                // 查询
                $accountBox.find('.search-hook').on('click', function () {
                    $($tableHookName).bootstrapTable('onCustomSearch');
                });
                $('.search-hook').on('click', function () {
                    $($tableHookName).bootstrapTable('onCustomSearch');
                });
                var $tableHook = $tableHookName.bootstrapTable({
                    scrollbar: 'order-table-body',
                    striped: true, // 设置为 true 会有隔行变色效果
                    pagination: true, // true 显示分页
                    paginationDetail: true, // 分页详情
                    sidePagination: 'server', // 服务器端
                    method: 'post',
                    url: URI.WORKORDER.ORDER.LIST,
                    debug: false,
                    cache: false,
                    pageNumber: 1,
                    pageSize: 20,
                    pageList: [10, 20, 50, 100],
                    // fixedColumns: true,
                    customButton: '',
                    customQueryParams: function (params) {
                        var formParams = $form.serializeJson();
                        var queryParams = $.extend({}, params, formParams);
                        //console.log(queryParams);
                        return queryParams;
                    },
                    onLoadSuccess: function (data) {
                        //console.log(JSON.stringify(data));
                    },
                    onLoadError: function (status, xhr) {
                    },
                    onCheckAll: function (rows) {
                        
                    },
                    onClickCell:function (field, value, row, $element) {
                        if (field == 'userName') { //单灯编号
                            M.Page.emit(URI.OPERATE.SINGLELAMP.DETAIL.PAGE);
                            IOT.setSessionStore(URI.OPERATE.SINGLELAMP.DETAIL.PAGE, JSON.stringify(row));
                            return false;
                        }
                    },
                    columns: [
                        /*{
                         field: '', checkbox: true, align: 'center', fixedLeft: true, width: 60,
                         events: {
                         'change .checkbox-hook': function (e, value, row, index) {
                         console.log('复选框: ' + value);
                         }
                         }
                         },*/
                        /*{
                         field: 'no', title: '序号', align: 'center', width: 50,tips:true,
                         formatter: function (value, row, index) {
                         var pageSize =  $accountBox.find(tableHookName).bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                         var pageNumber = $accountBox.find(tableHookName).bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                         return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                         }
                         },*/
                        {
                            field: 'mobile', title: '工单编号', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'userName', title: '单灯编号', align: 'center', fixedLeft: true,tips:true,
                            cellStyle:function () {
                                return { classes: 'active-url' }
                            }
                        },
                        {
                            field: 'gender', title: '来源', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'email', title: '故障类型', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'email', title: '当前状态', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'registerTime', title: '告警时间', align: 'center', fixedLeft: true,tips:true,
                            formatter: function (val, row, index) {
                                return val;
                            }
                        },
                        {
                            field: 'email', title: '告警编号', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'operate', title: '操作', align: 'center', fixedLeft: true,width: 180,
                            events: {
                                'click .detail-order': function (e, value, row, index) {
                                    M.Page.emit(URI.WORKORDER.ORDER.DETAIL.PAGE);
                                    IOT.setSessionStore(URI.WORKORDER.ORDER.DETAIL.PAGE, JSON.stringify(row));
                                    return false;
                                },
                                'click .sign-order': function (e, value, row, index) {
                                    M.Page.emit(URI.WORKORDER.ORDER.DETAIL.PAGE);
                                    IOT.setSessionStore(URI.WORKORDER.ORDER.DETAIL.PAGE, JSON.stringify(row));
                                    return false;
                                },
                                'click .dispose-order': function (e, value, row, index) {
                                    M.Page.emit(URI.WORKORDER.ORDER.DETAIL.PAGE);
                                    IOT.setSessionStore(URI.WORKORDER.ORDER.DETAIL.PAGE, JSON.stringify(row));
                                    return false;
                                },
                                'click .audit-order': function (e, value, row, index) {
                                    M.Page.emit(URI.WORKORDER.ORDER.DETAIL.PAGE);
                                    IOT.setSessionStore(URI.WORKORDER.ORDER.DETAIL.PAGE, JSON.stringify(row));
                                    return false;
                                },
                                'click .discard-order': function (e, value, row, index) {
                                    M.Page.emit(URI.WORKORDER.ORDER.DETAIL.PAGE);
                                    IOT.setSessionStore(URI.WORKORDER.ORDER.DETAIL.PAGE, JSON.stringify(row));
                                    return false;
                                },
                                'click .change-order': function (e, value, rowData, index) {
                                    M.Page.emit(URI.WORKORDER.ORDER.DETAIL.PAGE);
                                    IOT.setSessionStore(URI.WORKORDER.ORDER.DETAIL.PAGE, JSON.stringify(rowData));
                                    return false;
                                }
                            },
                            formatter: function (value, row, index) {
                                let html = [];
                                if (M.Authority.checkAuthority('account-detail')) {
                                    html.push('<a class="detail-order operate">详细</a>');
                                }
                                if (M.Authority.checkAuthority('account-modify')&&row.gender==1) {
                                    html.push('<a class="sign-order operate">签收</a>');
                                }
                                if (M.Authority.checkAuthority('account-delete')&&row.gender==0) {
                                    html.push('<a class="dispose-order operate">处理</a>');
                                }
                                if (M.Authority.checkAuthority('account-modify')&&row.gender==2) {
                                    html.push('<a class="audit-order operate">审核</a>');
                                }
                                if (M.Authority.checkAuthority('account-modify')&&row.gender==1) {
                                    html.push('<a class="discard-order operate">废弃</a>');
                                }
                                if (M.Authority.checkAuthority('account-modify')&&row.gender==1) {
                                    html.push('<a class="change-order operate">改派</a>');
                                }
                                return html.join('');
                            }
                        }
                    ]
                });
                //权限——查看
                if (!M.Authority.checkAuthority('account-detail')&&!M.Authority.checkAuthority('account-modify')) {
                    $(tableHookName).bootstrapTable('hideColumn', 'operate');//隐藏列
                }
            });
        }
    });
})();